package leetcode.editor.cn;

import utils.TreeNode;

/**
 * 左叶子之和
 * @author qulq
 * @date 2024-07-06 21:45:10
 */
public class T404_SumOfLeftLeaves{
	 public static void main(String[] args) {
	 	 //测试代码
	 	 Solution solution = new T404_SumOfLeftLeaves().new Solution();
	 }
	 
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int sumOfLeftLeaves(TreeNode root) {
		if (root == null) {
			return 0;
		}
		if (root.left == null && root.right == null) {
			return 0;
		}
		if (root.left != null && root.left.left == null && root.left.right == null) {
			// 左子树已经可以明确返回的情况
			return root.left.val + sumOfLeftLeaves(root.right);
		}
		return sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right);
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}